//
//  WKTherrThroughViewController.m
//  WKDemo
//
//  Created by wangzhaohui-Mac on 14-8-2.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKTherrThroughViewController.h"
#import "WKVoiceHttpTool.h"
#import "WKVoiceParam.h"
#import "WKVoiceResult.h"

@interface WKTherrThroughViewController ()
@property (nonatomic,strong) NSArray *statuses;
@end

@implementation WKTherrThroughViewController

#pragma mark - 懒加载
- (NSArray *)statuses
{
    if (_statuses == nil) {
        _statuses = [NSArray array];
    }
    return _statuses;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
//    [self loadNewData];
    
}
/**
 *  加载新数据
 */
- (void)loadNewData
{
    WKVoiceParam *param = [[WKVoiceParam alloc] init];
    
    [WKVoiceHttpTool getThrougNewDataListWithParam:param success:^(WKVoiceResult *result) {
        self.statuses = result.homeDatas;
        
        //显示底部刷新控件
        self.tableView.footerHidden = NO;
        //刷新数据
        [self.tableView reloadData];
        //停止下拉刷新
        [self.tableView headerEndRefreshing];
    } failure:^(NSError *error) {//停止下拉刷新
        [self.tableView headerEndRefreshing];
        WKLog(@"%@",error);
    }];
    
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.statuses.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    WKResult *result = self.statuses[indexPath.row];
    cell.textLabel.text = result.name;
    cell.detailTextLabel.text = result.passtime;
    
    [cell.imageView setImageWithURL:[NSURL URLWithString:result.profile_image] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    
    return cell;
    
}

@end
